﻿#!/bin/bash

# 检测 yum 镜像
check_yum_mirror() {
    # 获取当前配置的 yum 镜像
    yum_mirror=$(yum repolist | grep "mirrorlist" | awk '{print $1}')
    if [ "$yum_mirror" == "" ]; then
        # 如果没有配置镜像，尝试下载阿里云镜像
        url=https://mirrors.aliyun.com/repo/Centos-7.repo
        if ! curl -o /etc/yum.repos.d/CentOS-Base.repo $url; then
            echo "Failed to download the mirror file."
            exit 1
        fi
        # 清理 yum 缓存
        yum clean all
    else
        # 清理 yum 缓存
        yum clean all
    fi
}

check_yum_mirror

# 升级所有包，包括软件和系统内核
if ! yum -y update; then
    echo "Failed to update packages."
    exit 1
fi

# 安装 wget
if ! yum -y install wget; then
    echo "Failed to install wget."
    exit 1
fi
